package com.li.springbootproject.controller.transaction;

import com.li.springbootproject.service.transaction.TransactionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author LiDong
 * @version 1.0.0
 * @className TransactionController.java
 * @createTime 2021年06月07日 20:12:00
 */
@RestController
@RequestMapping("/transaction")
public class TransactionController {

    @Autowired
    private TransactionService transactionService;

    /**
     * 事务回滚测试
     */
    @RequestMapping("/one")
    public void transactionOne() {
        transactionService.ransactionOne();
    }

    /**
     * 事务失效
     */
    @RequestMapping("/two")
    public void transactionTwo() {
        transactionService.transactionTwo();
    }

    /**
     * 事务生效
     */
    @RequestMapping("/three")
    public void transactionThree() {
        new Thread(() -> {
            transactionService.transactionThree();
        }).start();
    }

    /**
     * 不同的事务提交锁表
     */
    @RequestMapping("/four")
    public void transactionFour() {
        transactionService.transactionFour();
    }

    /**
     * 解决上面的问题
     */
    @RequestMapping("/five")
    public void transactionFive() {
        transactionService.transactionFive();
    }
}
